package com.lanou.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou.entity.FM;
import com.lanou.entity.MyConsult;
import com.lanou.mapper.MyConsultMapper;
import com.lanou.service.MyConsultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @ClassName MyConsultServiceImpl
 * @Description TODO
 * @Author lizhenjiang
 * @Date 2025年08月14日 21:36
 * @Version 1.0
 */
@Service
public class MyConsultServiceImpl implements MyConsultService {
    @Autowired
    private MyConsultMapper myConsultMapper;

    @Override
    public int addMyConsult(MyConsult myConsult) {
        return myConsultMapper.insertMyConsult(myConsult);
    }

    @Override
    public int updateMyConsult(MyConsult myConsult) {
        // 从 myConsult 对象中提取 id 和 assessStatus 参数
        Integer id = myConsult.getId();
        String assessStatus = myConsult.getAssessStatus();

        // 调用 Mapper 的 updateStatus 方法，传递 id 和 assessStatus
        return myConsultMapper.updateStatus(id, assessStatus);
    }

    @Override
    public int deleteMyConsult(Integer id) {
        return myConsultMapper.deleteMyConsult(id);
    }

    @Override
    public PageInfo<MyConsult> getMyConsult(Integer userId, String status, Integer pageNum, Integer pageSize) {
        if(pageNum==null&&pageSize==null){
            PageInfo<MyConsult> pageInfo= new PageInfo<>(myConsultMapper.selectMyConsult(userId,status));
            return pageInfo;
        }
        PageHelper.startPage(pageNum, pageSize);
        List<MyConsult> myConsults=myConsultMapper.selectMyConsult(userId,status);
        PageInfo<MyConsult> pageInfo=new PageInfo<>(myConsults);
        return pageInfo;
    }
}
